enum MODEL{
    //%block="开启"
    1,
    //%block="关闭"
    0
}

enum PIN_Digital{
    //%block="2"
    21,
    //%block="3"
    22,
    //%block="4"
    23,
    //%block="5"
    24,
    //%block="6"
    32,
    //%block="7"
    15,
    //%block="8"
    14,
    //%block="9"
    13,
    //%block="10"
    12,
    //%block="11"
    11,
    //%block="12"
    10,
    //%block="13"
    3,
    //%block="0(RX)"
    4,
    //%block="1(TX)"
    5  
}

enum PIN_Analog{
    //%block="A0"
    33,
    //%block="A1"
    32,
    //%block="A2"
    35,
    //%block="A3"
    34,
    //%block="A4"
    39,
    //%block="A5"
    36
}

enum I2CPIN{
    //%block="SDA"
    31,
    //%block="SCL"
    30
}

enum ROUTE{
    //%block="超级玛丽"
    SuperMarie,
    //%block="魂斗罗"
    Contra,
    //%block="雪人兄弟"
    SnowBros,
    //%block="1944"
    1944
}


//% color="#004198" iconWidth=50 iconHeight=40
namespace NES{
    //% block="NES游戏初始化" blockType="command"
    //% VOLUME.shadow="range" VOLUME.params.min=1 VOLUME.params.max=10  VOLUME.defl=5
    export function NesInit(parameter: any, block: any) {	
		Generator.addImport("import nesgame",true);
		Generator.addCode(`nesgame.init()`);
    }


    //% block="PS2游戏手柄初始化 ：CS:[CS] CLK:[CLK] CMD:[CMD] DAT:[DAT]  游戏音量：[VOLUME]" blockType="command"
    //% CS.shadow="dropdown" CS.options="PIN_Digital" CS.defl="PIN_Digital.21"
    //% CLK.shadow="dropdown" CLK.options="PIN_Digital" CLK.defl="PIN_Digital.22"
    //% CMD.shadow="dropdown" CMD.options="PIN_Digital" CMD.defl="PIN_Digital.23"
    //% DAT.shadow="dropdown" DAT.options="PIN_Digital" DAT.defl="PIN_Digital.24"
    //% VOLUME.shadow="range" VOLUME.params.min=1 VOLUME.params.max=10  VOLUME.defl=5
    export function NesPS2Init(parameter: any, block: any) {
        let cs = parameter.CS.code; 
        let clk = parameter.CLK.code; 
        let cmd = parameter.CMD.code; 
        let dat = parameter.DAT.code; 
        let volume = parameter.VOLUME.code; 
        Generator.addCode(`nesgame.ps2(${cs},${clk},${cmd},${dat},${volume})`);
        
    }

    //% block="UART键盘初始化  游戏音量：[VOLUME]" blockType="command"
    //% VOLUME.shadow="range" VOLUME.params.min=1 VOLUME.params.max=10  VOLUME.defl=5
    export function NesKeyBoardInit(parameter: any, block: any) {
        let volume = parameter.VOLUME.code; 
        Generator.addCode(`nesgame.kb(${volume})`);
    }

    //% block="运行游戏[PATH]" blockType="command"
    //% PATH.shadow="string" PATH.defl="/sd/NES/SuperMarie.nes"
    export function NesRun(parameter: any, block: any) {
        let path = parameter.PATH.code; 
        Generator.addCode(`nesgame.run(${path})`);
    }
	
}
    